package com.cloud.point.designPattern.adapter;

import com.cloud.point.designPattern.adapter.notifyCategory.SmsNotifyService;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

/**
 * NotifyManager
 *
 * @author H
 * @version 1.0
 * @date 2024-03-28 14:05
 */
@Service
@Slf4j
public class NotifyManager implements InitializingBean {

    @Resource
    private SmsNotifyService SmsNotifyService;
    @Resource
    private SmsNotifyService MailNotifyService;
    private final Map<MessageType, NotifyService> messageMap = new HashMap<>();


    @Override
    public void afterPropertiesSet() throws Exception {
        messageMap.put(MessageType.SMS, SmsNotifyService);
        messageMap.put(MessageType.MAIL, MailNotifyService);
    }

    public void sendMessage(MessageType messageType, String accountId, String content) {
        NotifyService notifyService = messageMap.get(messageType);
        if (notifyService == null) {
            log.error("notify message not exist;{},{}", messageType, content);
        }
        notifyService.notifyMessage(accountId, content);
    }

}
